#!/bin/bash

# 配置参数
REMOTE_USER="server"
REMOTE_HOST="192.168.45.41"
REMOTE_PATH="/home/server/EquipServer"

# 构建和部署函数
echo "开始部署到树莓派..."

# 1. 同步代码到树莓派
echo "正在同步代码到树莓派..."
rsync -avz --exclude '__pycache__' --exclude '*.log' --exclude 'logs/' ./ ${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_PATH}/

# 2. 在远程树莓派上安装依赖
echo "正在安装依赖..."
ssh ${REMOTE_USER}@${REMOTE_HOST} "cd ${REMOTE_PATH} && pip3 install -r requirements.txt"

# 3. 重启服务
echo "正在重启服务..."
ssh ${REMOTE_USER}@${REMOTE_HOST} "sudo systemctl restart src/main.py"

echo "部署完成！"